package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.dto.inspect.InspectDto;
import com.lnking.lnkingplace.model.dto.meeting.MeetingDetailDto;
import com.lnking.lnkingplace.model.dto.meeting.MeetingExportDto;
import com.lnking.lnkingplace.model.request.inspect.InspectSearchRequest;
import com.lnking.lnkingplace.model.request.meeting.MeetingAddRequest;
import com.lnking.lnkingplace.model.request.meeting.MeetingSearchRequest;
import com.lnking.lnkingplace.model.request.meeting.MeetingUpdateRequest;
import com.lnking.lnkingplace.service.IMeetingService;
import com.lnking.lnkingplace.service.IMeetingService;
import com.lnking.starter.export.utils.ExportUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sn
 * @since 2022-09-18
 */
@Api(tags = "会议情况统计")
@RestController
@RequestMapping("/meeting")
public class MeetingController {

    @Autowired
    IMeetingService meetingService;

    @ApiOperation("新增")
    @PostMapping("/add")
    public ReturnResult add(@RequestBody @Valid MeetingAddRequest params) throws Exception {
        meetingService.add(params);
        return ReturnResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        meetingService.removeById(id);
        return ReturnResult.success();
    }

    @ApiOperation("编辑")
    @PostMapping("/update")
    public ReturnResult update(@RequestBody @Valid MeetingUpdateRequest params) throws Exception {
        meetingService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("查询列表")
    @GetMapping("/list")
    public ReturnResult getList(MeetingSearchRequest params) {
        return ReturnResult.success(meetingService.pageList(params));
    }


    @ApiOperation("获取会议情况统计详情")
    @GetMapping("/{id}")
    public ReturnResult getDetail(@PathVariable("id") String id) {
        MeetingDetailDto user = meetingService.getDetailById(id);
        return ReturnResult.success(user);
    }


    /**
     * TODO
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation("导入excel")
    @PostMapping(value = "/import")
    public ReturnResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        meetingService.importExcel(file);
        return ReturnResult.success();
    }

    @ApiOperation(value = "导出")
    @GetMapping(value = "/export")
    public void exportInfo(MeetingSearchRequest params, HttpServletResponse response) throws Exception {
        ExportUtils.export((List<MeetingExportDto>) meetingService.pageList(params), response, MeetingExportDto.class);
    }
}
